var zTreeObj;
var cNode;
var setting = {
		check : {
			enable : false
		},
		async : {
			enable : true,
			url : "newscatalog/news-catalog!listbyparent",
			autoParam : [ "id=bean.id" ],
			otherParam : {}
		},
		callback : {
			onClick:zTreeOnClick
		}
	};
	var root = {
		name : "所有新闻分类",
		open : true,
		nocheck : false,
		id : "root",
		isParent : true
	};
$(function(){
		
	$("#date").datepicker({"dateFormat":"yy-mm-dd"});	
	var zNodes = [ root ];
	zTreeObj = $.fn.zTree.init($("#resTree"), setting, zNodes);
	var nodes = zTreeObj.getNodes();
	zTreeObj.expandNode(nodes[0], null, false, false, true);
	
	$("#externalcheck").bind('click',function(){
		$("#beanhref").attr("disabled",!this.checked);
		$("#beanhref").toggle();
	});
	$("#saveBtn").bind("click",function(){
		var cid = $("#parentId").val();
		if(cid==null || cid==""){
			alert("请先选择一个新闻分类!");
			return;
		}
		submitAll();
		
	});
	
	$("#listBtn").bind("click",function(){
		doGet("newscatalog/list");
	});
	
});
function zTreeOnClick(event, treeId, treeNode) {
	 $("#parentId").val(treeNode.id);         
     $("#cname").text(treeNode.name); 
}
function submitAll(){
	var ext = $("#externalcheck").attr("checked");
	if(ext){
		var href = $("#beanhref");
		if(href.val()==''){
			alert("如果是外部连接，url属性必须填写");
			return ;
		}
	}
	var data = $("#NewsCatalogForm").serialize();
	var url = "newscatalog/news-catalog!add";
	doSubmit(url,data);
}